﻿using HandyControl.Controls;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfAGVSystem.Common;

namespace WpfAGVSystem.ViewModels
{
    public class WarningMsgViewModel : BindableBase, IDialogAware
    {

        public String Pwd { get; set; }
        private SettingPara settingPara1;
        private string title = "谨慎关闭";

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private string content = "信息内容";

        public event Action<IDialogResult> RequestClose;

        public string Content
        {
            get { return content; }
            set { content = value; }
        }


        private bool isOpenMask = true;

        public bool IsOpenMask
        {
            get { return isOpenMask; }
            set { isOpenMask = value; }
        }


        public DelegateCommand ConfirmCommand { get; set; }
        public DelegateCommand CancelCommand { get; set; }

        public WarningMsgViewModel(SettingPara _settingPara)
        {
            ConfirmCommand = new DelegateCommand(Ok);
            CancelCommand = new DelegateCommand(Cancel);
            settingPara1= _settingPara;
        }

        private void Cancel()
        {
            OnDialogClosed();
        }

        private void Ok()
        {
            //  IsClosedMask();
            if (settingPara1.Pwd == Pwd)
            {
                DialogParameters param = new DialogParameters();
                param.Add("resultMsg", "ok");
                RequestClose?.Invoke(new DialogResult(ButtonResult.OK, param));
            }
            else 
            {
                Growl.Info("密码错误");
            }
            
        }

        public void IsClosedMask()
        {

            if (IsOpenMask)
            {
              //  DialogsEx.DialogMask(false);
            }
        }

        public bool CanCloseDialog()
        {

            return true;
        }

        public void OnDialogClosed()
        {
            IsClosedMask();
            DialogParameters param = new DialogParameters();
            param.Add("resultMsg", "no");
            RequestClose?.Invoke(new DialogResult(ButtonResult.No, param));
        }


        public void OnDialogOpened(IDialogParameters parameters)
        {

            if (parameters.ContainsKey("IsOpenMask"))
                IsOpenMask =true;

            if (IsOpenMask == true)
            {
                
               // DialogsEx.DialogMask(true);
            }
            
            if (parameters.ContainsKey("Title"))
                Title = parameters.GetValue<string>("Title");

            if (parameters.ContainsKey("Content"))
                Content = parameters.GetValue<string>("Content");
        }
    }
}
